<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="充电站名称">
              <a-input placeholder="请输入充电站名称" v-model="queryParam.siteName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="简称">
              <a-input placeholder="请输入简称" v-model="queryParam.shortName"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="省">
                <!-- <a-input placeholder="请输入电价" v-model="queryParam.provinceId"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入所属省"
                  v-model="queryParam.provinceId">
                  <a-select-option v-for="(province,provinceindex) in provinceList" :key="provinceindex.toString()" :value="province.id"  @click="queryCityList(province.id)">
                    {{ province.provinceName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="市">
                <!-- <a-input placeholder="请输入市" v-model="queryParam.cityId"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入所属市"
                  v-model="queryParam.cityId">
                  <a-select-option v-for="(city,cityindex) in cityList" :key="cityindex.toString()" :value="city.id" @click="queryDistrictList(city.id)">
                    {{ city.cityName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="区">
                <!-- <a-input placeholder="请输入区" v-model="queryParam.districtId"></a-input>-->
                <a-select
                  style="width: 100%"
                  placeholder="请输入所属区"
                  v-model="queryParam.districtId">
                  <a-select-option v-for="(district,districtindex) in districtList" :key="districtindex.toString()" :value="district.id">
                    {{ district.districtName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="运行状态">
                <a-select
                  style="width: 100%"
                  placeholder="请输入运行状态"
                  v-model="queryParam.status">
                    <a-select-option :value="1" >运行</a-select-option>
                    <a-select-option :value="0">停止</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
        </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
     <!-- <a-button @click="ssss" type="primary" icon="plus">新增1111</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('站点信息')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <!--<a-button @click="handleAdd" type="primary" icon="plus">获取充电站位置</a-button>-->
      <a-button type="primary" icon="plus" @click="jumpMap">获取充电站位置坐标</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="imatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <img :src="getImgView(record.status)"/>
          </div>
        </template>
        <template slot="impicpathlot" slot-scope="text, record, index">
          <div class="anty-img-wrap" >
            <img width="50px" height="50px" :src="getImgView(record.picPath)" :preview="getImgView(record.picPath)"/>
          </div>
        </template>
        <template slot="siteName" slot-scope="text, record, index">
          <div class="anty-img-wrap" >
            <a  @click="viewMap(record)">{{record.siteName}}</a>
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a @click="camreaModal(record)">监控</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <wxcChargingSite-modal ref="modalForm" @ok="modalFormOk"></wxcChargingSite-modal>
    <CreateMapModal ref="CreateMapModal"></CreateMapModal>
    <CameraModal ref="CameraModal"></CameraModal>
<!--    <view-map-modal ref="ViewMapModal"></view-map-modal>-->
    <ViewMapModal ref="ViewMapModal"></ViewMapModal>
  </a-card>
</template>

<script>
  import WxcChargingSiteModal from './modules/WxcChargingSiteModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { postAction } from '@/api/manage'
  import CreateMapModal from "./modules/CreateMapModal";
  import ViewMapModal from "./modules/ViewMapModal";
  import CameraModal from "./modules/CameraModal";

  export default {
    name: "WxcChargingSiteList",
    mixins:[JeecgListMixin],
    components: {
      CreateMapModal,
      WxcChargingSiteModal,
      CameraModal,
      ViewMapModal
    },
    data () {
      return {
        description: '站点信息管理页面',
        provinceList:[],
        cityList:[],
        districtList:[],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '充电站名称',
            align:"center",
            dataIndex: 'siteName',
         scopedSlots: {customRender: "siteName"}
           },
		   {
            title: '简称',
            align:"center",
            dataIndex: 'shortName'
           },
		   {
            title: '省份',
            align:"center",
            dataIndex: 'provinceId'
           },
		   {
            title: '市',
            align:"center",
            dataIndex: 'cityId'
           },
		   {
            title: '区县',
            align:"center",
            dataIndex: 'districtId'
           },
		   {
            title: '地理位置',
            align:"center",
            dataIndex: 'sitePosition'
           },
/*		   {
            title: 'X坐标',
            align:"center",
            dataIndex: 'coordinateX'
           },
		   {
            title: 'Y坐标',
            align:"center",
            dataIndex: 'coordinateY'
           },*/
		   {
            title: '直流桩台数',
            align:"center",
            dataIndex: 'dcpileCount'
           },
		   {
            title: '交流桩台数',
            align:"center",
            dataIndex: 'acpileCount'
           },
		   /*{
            title: '电价',
            align:"center",
            dataIndex: 'chargingPrice'
           },
		   {
            title: '计费方式',
            align:"center",
            dataIndex: 'chargeMode'
           },
		   {
            title: '停车收费',
            align:"center",
            dataIndex: 'parkingCharge'
           },
		   {
            title: '对外开放',
            align:"center",
            dataIndex: 'opening'
           },
		   {
            title: '功能设施',
            align:"center",
            dataIndex: 'service'
           },
		   {
            title: '电话',
            align:"center",
            dataIndex: 'tel'
           },*/
          {
            title: '站点风采',
            align:"center",
            dataIndex: 'picPath',
            scopedSlots: {customRender: "impicpathlot"}

          },
		   {
            title: '监控IP',
            align:"center",
            dataIndex: 'loginIp'
           },
/*		   {
            title: '监控端口',
            align:"center",
            dataIndex: 'port'
           },
		   {
            title: '监控用户名',
            align:"center",
            dataIndex: 'userName'
           },
		   {
            title: '监控密码',
            align:"center",
            dataIndex: 'password'
           },
		   {
            title: '设备端口',
            align:"center",
            dataIndex: 'devicePort'
           },
		   {
            title: '电站描述',
            align:"center",
            dataIndex: 'remark'
           },*/

          {
            title: '运行状态',
            align:"center",
            dataIndex: 'status',
            onclick:"dianji()",
            scopedSlots: {customRender: "imatarslot"}
          },
/*		   {
            title: '删除状态',
            align:"center",
            dataIndex: 'delFlag'
           },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
      imgerver: window._CONFIG['domianURL'] + "/sys/common/view",
      list: "/wxcchargingsite/wxcChargingSite/list",
      delete: "/wxcchargingsite/wxcChargingSite/delete",
      deleteBatch: "/wxcchargingsite/wxcChargingSite/deleteBatch",
      exportXlsUrl: "wxcchargingsite/wxcChargingSite/exportXls",
      importExcelUrl: "wxcchargingsite/wxcChargingSite/importExcel",
      provinceListUrl:"/dictionary/dictionary/provinceList",
      cityListUrl:"/dictionary/dictionary/cityList",
      districtListUrl:"/dictionary/dictionary/districtList",
      fileUpload: window._CONFIG['domianURL']+"/sys/common/upload",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      this.queryProvinceList();
      this.queryCityList();
      this.queryDistrictList();
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      getImgView: function (imgpath) {
        if(imgpath ==0){
          imgpath ="user/20190513/pumpstop_1557715815386.gif";
        }else if(imgpath ==1){
          imgpath ="user/20190513/pumpwork_1557715791637.gif";
        }
        return this.url.imgerver + "/" + imgpath;
      },
      queryProvinceList(){
        postAction(this.url.provinceListUrl).then((res)=>{
          if(res.success){
            this.provinceList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      queryCityList(provinceId){
        let params = {provinceId:provinceId}
        postAction(this.url.cityListUrl,params).then((res)=>{
          if(res.success){
            this.cityList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      queryDistrictList(cityId){
        let params = {cityId:cityId}
        postAction(this.url.districtListUrl,params).then((res)=>{
          if(res.success){
            this.districtList = res.result;
          }else{
            console.log(res.message);
          }
        }).catch((err) => {
          this.$message.error("请求异常："+err)
        })
      },
      jumpMap: function () {
        this.$refs.CreateMapModal.add();
      },
      camreaModal(record){
        this.$refs.CameraModal.add(record);
      },
      viewMap(record){
        alert(record.coordinateX+"=========="+record.coordinateY);
        this.$refs.ViewMapModal.add(record);

      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>